package com.zrh.jsd.service.studydemo.local_persistence;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileWriterSaveFile {
    static String filename = "D:/string.txt";

    public static void main(String[] args) throws IOException {
        // 1.创建FileWriter对象
        FileWriter fw = new FileWriter("D:/string.txt", true);
        // 2.调用write方法写数据
        fw.write("Hello,World!");
        // 3.关闭数据流
        fw.close();


        String data = "This content will append to the end of the file";
        File file = new File("zrhlvoe.txt");
        //if file doesnt exists, then create it
        if (!file.exists()) {
            file.createNewFile();
        }
        System.out.println(file.getAbsolutePath());
        System.out.println(file.getName());
        //true = append file
        FileWriter fileWritter = new FileWriter("zrhlvoe.txt", true);
        fileWritter.write(data);
        fileWritter.close();

    }
}
